// 引入vue
import Vue from 'vue'
// 引入路由模块
import VueRouter from 'vue-router'
// 路由加入vue中
Vue.use(VueRouter);

// 设置路由
import Home from "../views/home.vue"
import Login from "../views/login.vue"
import Reg from "../views/reg.vue"
import User from "../views/user"
import uInfo from "../views/user/info.vue"
import AddressList from "../views/user/address-list.vue"
import AddressEdit from "../views/user/address-edit.vue"
import AddressAdd from "../views/user/address-add.vue"
import Cate from "../views/cate"
import Cart from "../views/cart/index.vue"
import Good from "../views/good"
import Detail from "../views/good/detail.vue"
import Comment from "../views/good/comment.vue"
import gInfo from "../views/good/info.vue"
import NoPage from "../views/no-page.vue"


let routes = [
    {
        path: '/home',
        component: Home,
        name: 'home'
    },
    {
        path: '/cart',
        component: Cart,
        name: 'cart'
    },
    {
        path: '/good',
        component: Good,
        children: [{
                path: ':id',
                component: gInfo,
                name: 'info'
            },
            {
                path: ':id/detail',
                component: Detail,
                name: 'detail'
            },
            {
                path: ':id/comment',
                component: Comment,
                name: 'comment'
            },
            {
                path: '/',
                redirect: ':id'
            }
        ]
    },
    {
        path: '/cate',
        component: Cate,
        name: 'cate'
    },
    {
        path: '/login',
        component: Login,
        name: 'login'
    },
    {
        path: '/reg',
        component: Reg,
        name: 'reg'
    },
    {
        path: '/user',
        component: User,
        name: 'user',
        children: [
            {path:'info',component: uInfo},
            {path:'addressList',component: AddressList},
            {path:'addressEdit',component: AddressEdit},
            {path:'addressAdd',component: AddressAdd},
            {path:'/',redirect:'info'}
        ]
    },
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '*',
        component: NoPage,
        // beforeEnter:(to,from,next)=>{
        //     store.commit(UPDATE_LOADING,false)
        //     store.commit(UPDATE_HEADER,false)
        //     next()
        // }   
    }
];

// 实例路由
let router = new VueRouter({
    routes,
    mode: 'history'
});

export default router;